<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>construct</title>
  </head>
  <body></body>
</html>
<script>
  class User {
    constructor(name, age) {
      this.name = name;
      this.age = age;
    }
  }
  const proxyUser = Reflect.construct(User, ["王五", 18]); // 通过代理生成实例
  const user = new User("王五", 18); // 不通过代理生成实例
  console.log("proxyUser", proxyUser);
  console.log("user", user);

  // 原理 - 代理生成实例
  const ProxyUser = new Proxy(User, {
    construct(...args) {
      const user = Reflect.construct(...args);
      return user;
    },
  });

  const userZhang = new ProxyUser("张三", 30);
  console.log("user1", userZhang);
</script>
